/**
 * Copyright (c)  HeiFeiDeFengZheng.Co.Ltd. All rights reserved.
 **/
package com.defu.studentmanage.exception;

import com.alibaba.druid.support.logging.LogFactory;
import com.defu.studentmanage.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 功能描述：
 *
 * @author huifeidefengzheng
 * @since 2024-01-25
 *
 **/
@Slf4j
@ControllerAdvice(basePackages = "com.defu.studentmanage.controller")
public class GlobalExceptionHander {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(HttpServletRequest request, Exception ex) {
        log.info("ERROR: " , ex);
        return Result.fail(ex.getMessage());
    }


    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Result customException(HttpServletRequest request, CustomException ex) {
        log.info("ERROR: " , ex);
        return Result.fail(ex.getMessage());
    }
}
